import net.spreadshirt.shop.Shop;
import net.spreadshirt.view.View;

/**
 * The Controller class provides a collection of wrapper functions
 * which are simply designed to separate and disconnect
 * the view layer from the model (a.k.a. shop) and vice versa.
 * 
 * The controller receives user based input from the view layer
 * and modifies the model (the shop class).
 */
class net.spreadshirt.controller.Controller {

	// These variables stores the instances for the view and the shop.
	public var view:View;
	public var shop:Shop;

	/**
	 * Controller Constructor
	 */
	public function Controller() {
	}

	/**
	 * Starts initializing the view for example the user interface.
	 */
	public function init():Void  {
		view.init();
	}

	/**
	 * Starts initializing the model when finished loading view components.
	 */
	public function onViewLoaded():Void  {
		shop.init();
	}

	/**
	 * Returns the shop ID.
	 * 
	 * @return	The shop ID.
	 */
	public function getShopID():Number {
		return shop.shop_id;
	}

	/**
	 * Returns a single article item.
	 * 
	 * @param	article_id	The article ID.
	 * 
	 * @return	A single article item.
	 */
	public function getArticleItem(article_id:Number):Object {
		return shop.getArticleItem(article_id);
	}

	/**
	 * Returns all article items of a specified category.
	 * 
	 * @param	category_id	The category ID.
	 * 
	 * @return	An array of article items.
	 */
	public function getArticleItemsByCategory(category_id:Number):Array {
		return shop.getArticleItemsByCategory(category_id);
	}

	/**
	 * Returns all design items.
	 * 
	 * @return	An array of all design items.
	 */
	public function getDesignItems():Array {
		return shop.getDesignItems();
	}

	/**
	 * Returns a single design item.
	 * 
	 * @param	design_id	The design ID.
	 * 
	 * @return	A single design item.
	 */
	public function getDesignItem(design_id:Number):Object {
		return shop.getDesignItem(design_id);
	}

	/**
	 * Returns all category items.
	 * 
	 * @return	An array of category items.
	 */
	public function getCategoryItems():Array {
		return shop.getCategoryItems();
	}

	/**
	 * Adds an item to the basket.
	 * 
	 * @param	article_id	The items article ID.
	 * @param	quantity	The number of pieces.
	 * @param	producttype_size_id	The size ID of the item.
	 * @param	producttype_color_id	The color ID of the item.
	 */
	public function addBasketitem(
		article_id:Number,
		quantity:Number,
		producttype_size_id:Number,
		producttype_color_id:Number
	):Void {
		shop.addBasketitem(
			article_id,
			quantity,
			producttype_size_id,
			producttype_color_id
		);
	}

	/**
	 * Removes an item from the basket.
	 * 
	 * @param	basketitem_id	The ID of the basket item.
	 */
	public function removeBasketItem(basketitem_id:Number):Void {
		shop.updateBasketitem(basketitem_id, 0, null, null);
	}

	/**
	 * Modify the values of the selected item.
	 * 
	 * @param	basketitem_id	The ID of the basket item.
	 * @param	quantity	The number of pieces.
	 * @param	producttype_size_id	The size ID.	 * @param	producttype_color_id	The color ID.
	 */
	public function updateBasketItem(
		basketitem_id:Number,
		quantity:Number,
		producttype_size_id:Number,
		producttype_color_id:Number
	):Void {
		shop.updateBasketitem(
			basketitem_id,
			quantity,
			producttype_size_id,
			producttype_color_id);
	}

	/**
	 * Accepts the terms and conditions.
	 */
	public function acceptTNC():Void {
		shop.acceptTNC();
	}

	/**
	 * Returns the terms and conditions.
	 * 
	 * @return The terms and conditions string.
	 */
	public function getTNC():String {
		return shop.getTNCText();
	}

	/**
	 * Starts the order process.
	 */
	public function submitOrder():Void {
		shop.submitOrder();
	}
}
